home *** CD-ROM | disk | FTP | other *** search
- /*
- * fill and process an input buffer
- * called only when fp->_cnt < 0
- *
- * ++jrb bammi@dsrgsun.ces.cwru.edu
- */
-
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <sys/types.h>
- #include <unistd.h>
-
- int _filbuf(fp)
- FILE *fp;
- {
- register unsigned int f;
- register long got;
-
- f = fp->_flag;
- if(f & _IORW) f = (fp->_flag |= _IOREAD);
- if(!(f & _IOREAD) || (f & (_IOERR | _IOEOF)))
- return(EOF);
-
- /* if this is stdin & a tty, and stdout is line buffered, flush it */
- if((fp == stdin) && (f & _IODEV) && (stdout->_flag & _IOLBF))
- (void)fflush(stdout);
-
- if((got = lread(fp->_file, fp->_base, (long)fp->_bsiz)) <= 0)
- { /* EOF or error */
- fp->_flag |= ((got == 0) ? _IOEOF : _IOERR);
- return EOF;
- }
- fp->_cnt = got - 1;
- fp->_ptr = fp->_base + 1;
- return *(fp->_base);
- }
-